package com.gzck.gzck_verson2.controller;


import cn.dev33.satoken.util.SaResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gzck.gzck_verson2.pojo.GProjectInfo;
import com.gzck.gzck_verson2.pojo.GProjectType;
import com.gzck.gzck_verson2.pojo.page.MyPage;
import com.gzck.gzck_verson2.service.IGProjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 工程信息 前端控制器
 * </p>
 *
 * @author 任永辉
 * @since 2024-01-06
 */
@RestController
@RequestMapping("/g-project-info")
@CrossOrigin(origins = "*")
public class GProjectInfoController {

    @Autowired
    private IGProjectInfoService gProjectInfoService;

    // 添加工程信息
    @PostMapping("/add")
    public SaResult addProjectInfo(@RequestBody GProjectInfo projectInfo) {
        return gProjectInfoService.saveProjectInfo(projectInfo);
    }

    // 删除工程信息
    @DeleteMapping("/delete/{id}")
    public boolean deleteProjectInfo(@PathVariable Long id) {
        return gProjectInfoService.removeById(id);
    }

    // 更新工程信息
    @PutMapping("/update")
    public boolean updateProjectInfo(@RequestBody GProjectInfo projectInfo) {
        return gProjectInfoService.updateById(projectInfo);
    }

    // 查询单个工程信息
    @GetMapping("/{id}")
    public GProjectInfo getProjectInfo(@PathVariable Long id) {
        return gProjectInfoService.getById(id);
    }

    // 查询所有工程信息
    @GetMapping("/all")
    public List<GProjectInfo> getAllProjectInfos() {
        return gProjectInfoService.list();
    }

    //分页条件查询
    @PostMapping("/page")
    public IPage<GProjectInfo> page(@RequestBody MyPage<GProjectInfo> projectType) {
        return gProjectInfoService.pageByCondition(projectType);
    }
}
